<template>
	<el-container>
		<el-header>
            <div class="left-panel">
                <div class="finish">
                    <div class="finishNum">合计:
                        <div class="text">{{ total_stock }}</div>
                    </div>
                </div>
            </div>
			<div class="right-panel">
				<div class="right-panel-search">
					<!-- <el-input v-model="search.goods_name" placeholder="品名" clearable @keyup.enter="upsearch"></el-input> -->
                    <sc-auto-complete style="margin:5px;width: 180px" v-model="search.goods_name" :api="$API.basic.goods.list" :params-key="'name'" :rows-key="'rows'" :value-key="'name'" placeholder="品名" @select="getGoods"/>
                    <el-select v-model="search.ware_id" placeholder="请选择" filterable clearable>
                        <el-option v-for="item in wareList" :key="item.id" :label="item.ware_name" :value="item.id"></el-option>
                    </el-select>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                    <el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" border stripe @setExtend="setExtend" show-summary :params="{cate_stock: 1,is_send: 0}">
				<el-table-column type="selection" width="60" align="center"></el-table-column>
				<el-table-column label="仓库" prop="ware.ware_name" align="center"></el-table-column>
				<el-table-column label="品名" prop="goods_name" align="center"></el-table-column>
				<el-table-column label="库存(匹)" prop="curr_stock" align="center" width="120"></el-table-column>
				<el-table-column label="操作" align="center" width="120">
					<template #default="scope">
						<div class="buttonFlex">
							<el-button type="primary" size="small" @click="table_show(scope.row, scope.$index)" v-auth="'stockware.show'">详情</el-button>
                        </div>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save = false" :query="{ware_id: ware_id, goods_name: goods_name,flower_color: 1,is_send: 0}"></save-dialog>

</template>

<script>
import saveDialog from './save'

export default {
	name: 'dept',
	components: {
		saveDialog,
	},
	data() {
		return {
			dialog: {
				save: false
			},
			apiObj: this.$API.ware.ware.stock_inspect.list,
			selection: [],
			search: {
				ware_id: null,
				goods_name: null,
			},
            wareList: [],
            total_stock: 0,
            ware_id: "",
            goods_name: "",
		}
	},
    mounted() {
		this.getWare();
    },
	methods: {
        setExtend(data) {
            this.total_stock = data.count
        },
		//查看
		table_show(row) {
            this.ware_id = row.ware_id
            this.goods_name = row.goods_name
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('show')
			})
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        refresh() {
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.$refs.table.upData(this.search)
        },
		//本地更新数据
		handleSaveSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		},
        // 仓库
		async getWare() {
			var res = await this.$API.basic.ware.all.get();
			this.wareList = res.data
		},

        getGoods(data){
            this.search.goods_name = data.name
            this.upsearch()
        },
	}
}
</script>

<style></style>
